//
//  UIBarButtonItem+ZBarButtonItem.m
//  OC-weibo
//
//  Created by zero on 17/3/19.
//  Copyright © 2017年 zero. All rights reserved.
//

#import "UIBarButtonItem+ZBarButtonItem.h"

@implementation UIBarButtonItem (ZBarButtonItem)


+ (instancetype)initWithTitle:(NSString *)title andImageName:(NSString *)imageName andTarget:(id)target andSel:(SEL)sel{
    
    
    UIButton *btn = [[UIButton alloc] init];
    
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState:UIControlStateHighlighted];
    
    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    
    [btn sizeToFit];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barItem;
}
@end
